import ajax from '@/utils/ajax.js'
import store from 'store'

// 用户微信登录
export const wxLogin = async (wxCode) => {
	return ajax({
		url: '/base/user/user/loginWx',
		data: {
			wxCode
		},
		method: "POST"
	})
	console.log(res);
	if (res.code != 200) {
		return
	}


	// console.log(store);

}

// 查询当前用户会员信息
export const memberInfo = (data) => {
	return ajax({
		url: `/base/user/member/userid`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		data
	})
}

// 查询本人订单列表及详情表
export const ordersList = (data) => {
	console.log(store);
	return ajax({
		url: `/base/user/orders/list`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		data
	})
}

// 获取本人订单详细信息
export const orderInfo = (id) => {
	return ajax({
		url: `/base/user/orders/${id}`,
		header: {
			authentication: store.getters.getUserInfo.token
		}
	})
}

// 获取订单明细详细信息
export const orderDetail = (id) => {
	return ajax({
		url: `/base/user/detail/${id}`,
		header: {
			authentication: store.getters.getUserInfo.token
		}
	})
}

// 获取用户信息详细信息
export const userInfo = (id) => {
	return ajax({
		url: `/base/user/user/${id}`,
		header: {
			authentication: store.getters.getUserInfo.token
		}
	})
}

// 修改用户信息
export const alterUser = (data) => {
	return ajax({
		url: `/base/user/user`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		data,
		method: "PUT"
	})
}

// 新增收藏
export const addCollection = (data) => {
	return ajax({
		url: `/base/user/collection`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		data,
		method: "POST"
	})
}

// 查询收藏列表
export const getCollection = () => {
	return ajax({
		url: `/base/user/collection/list`,
		header: {
			authentication: store.getters.getUserInfo.token
		}
	})
}

// 查询收藏列表
export const delCollect = (ids) => {
	return ajax({
		url: `/base/user/collection/${ids}`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		method: 'DELETE'
	})
}

// 修改商品
export const updataGoods = (data) => {
	return ajax({
		url: `/base/admin/commodity`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		data,
		method: "PUT"
	})
}

// 获取卡券列表
export const getCouponList = () => {
	return ajax({
		url: `/base/user/coupon/list`,
		header: {
			authentication: store.getters.getUserInfo.token
		}
	})
}

// 查询当前用户优惠券
export const getUserCouponList = () => {
	return ajax({
		url: `/base/user/coupons/list`,
		header: {
			authentication: store.getters.getUserInfo.token
		}
	})
}

// 通过优惠券id查询优惠券
export const getCouponInfo = (id) => {
	return ajax({
		url: `/base/user/coupons/${id}`,
		header: {
			authentication: store.getters.getUserInfo.token
		}
	})
}

// 用户领取优惠券
export const getCoupon = (data) => {
	return ajax({
		url: `/base/user/coupons`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		data,
		method: "POST"
	})
}

// 用户下单
export const placeAnOrder = (data) => {
	return ajax({
		url: `/base/user/orders`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		data,
		method: "POST"
	})
}

// 订单支付
export const payAnOrder = (data) => {
	return ajax({
		url: `/base/user/orders/payment`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		data,
		method: "PUT"
	})
}

// 取消订单
export const cancelAnOrder = (number) => {
	return ajax({
		url: `/base/user/orders/cancel?number=${number}`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		method: "POST"
	})
}

// 申请退款
export const userRefund = (data) => {
	return ajax({
		url: `/base/user/orders/refund`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		data,
		method: "POST"
	})
}

// 确认收货 
export const userReceipt = (data) => {
	return ajax({
		url: `/base/user/orders/receipt`,
		header: {
			authentication: store.getters.getUserInfo.token
		},
		data,
		method: "POST"
	})
}

// 查询个人团购列表
export const groupList = () => {
	return ajax({
		url: `/base/user/buy/historylist`,
		header: {
			authentication: store.getters.getUserInfo.token
		}
	})
}

// 获取用户手机号
export const userphone = (code) => {
	return ajax({
		url: `/base/user/user/getPhone/${code}`,
		header: {
			authentication: store.getters.getUserInfo.token
		}
	})
}

// 生成用户二维码
export const userQrCode = (id) => {
	return ajax({
		url: `/base/user/user/getQrCode/${id}`,
		header: {
			authentication: store.getters.getUserInfo.token
		}
	})
}

// 购买员工或会员分享商品会变成会员
export const bindmember = (data) => ajax({
	url: `/base/user/member/bind`,
	header: {
		authentication: store.getters.getUserInfo.token
	},
	method: 'POST',
	data
})